package br.com.inventario.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class AutorizadorInterceptor extends HandlerInterceptorAdapter {
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object Controller) throws Exception {
		String uri = request.getRequestURI();
		
		if(uri.endsWith("MostraAutenticar") || uri.endsWith("EfetuaLogin") || uri.endsWith(".css") || uri.endsWith(".jpg")){
			return true;
		}
		
		if(request.getSession().getAttribute("usuarioLogado") != null){
			return true;
		}
		
		response.sendRedirect("MostraAutenticar");
		return false;
	}

}
